<?php
namespace app\api\controller;
use think\Db;

class Active extends Common
{
//  轮播
    public function banner(){
        $res = $this->select(['is_show'=>1],'sort desc,id desc');
        return $res;
    }

//  分类
    public function cateList(){
        $res = $this->select(['is_show'=>1],'sort desc,create_time desc');
        $res = obj_decode($res);
        if($res['code']){
            $data = $res['data'];
            foreach ($data as $k=>$v){
                if($k>3){
                    unset($res['data'][$k]);
                }
            }
        }
        return json( $res );
    }


//  分类详情
    public function cate(){
        $params = $this->params;
        $res = $this->read($params['cate_id'],['is_show'=>1]);
        return $res;
    }

//  往期活动文章
    public function historyArticle(){
        $params = $this->params;
        $res = $this->page($params['page'],$params['size'],['is_show'=>1],
            'sort desc,article_time desc,id desc');
        return $res;
    }

//  分类活动文章
    public function cateArticle(){
        $params = $this->params;
        $search = '"id":' . $params['cate_id'];
        $res = $this->page($params['page'],$params['size'],['is_show'=>1,'cate_title'=>['like',"%{$search}%"]],
            'sort desc,article_time desc,id desc');
        return $res;
    }

//  文章详情
    public function detailArticle(){
        $params = $this->params;
        $res = obj_decode( $this->read($params['art_id'],['is_show'=>1]) );
        if($res['code']==1){
            $res['data']['create_time'] = $res['data']['article_time'];
        }
        return json( $res );
    }

//  活动报名文章
    public function applyList(){
        $params = $this->params;
        $res = $this->page($params['page'],$params['size'],['is_show'=>1,'is_active'=>1],
        'sort desc,article_time desc,id desc');
        return $res;
    }

}